<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="common/include :: header('服务单项列表')" />
</head>
<body class="gray-bg">
	<div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="employee-form">
					<div class="select-list">
						<ul>
							<li>
								关键字：<input type="text" name="keyword"/>
							</li>

							<li>
								是否超管：
								<select name="isAdmin">
									<option value="">所有</option>
									<option value="0">否</option>
									<option value="1">是</option>
								</select>
							</li>
							<li>
								是否冻结：
								<select name="isFrozen">
									<option value="">所有</option>
									<option value="0">否</option>
									<option value="1">是</option>
								</select>
							</li>
							<li>
								所在部门：
								<select name="deptId">
									<option value="">所有</option>
									<option th:each="department : ${departments}" th:text="${department.name}" th:value="${department.id}"></option>
								</select>
							</li>
							<li>
								入职时间：
								<input name="startTime" class="form-control queryTime" placeholder="开始时间" type="text" required>
								-
								<input name="endTime" class="form-control queryTime" placeholder="结束时间" type="text" required>
							</li>

							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
							    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			
			<div class="btn-group-sm" id="toolbar" role="group">
				<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="business:employee:add">
	                <i class="fa fa-plus"></i> 新增
	            </a>

			</div>
	        
	        <div class="col-sm-12 select-table table-striped">
			    <table id="bootstrap-table"></table>
			</div>
		</div>
	</div>

	<th:block th:include="common/include :: footer" />
	<th:block th:include="common/include :: datetimepicker" />
	<script th:inline="javascript">
		var prefix = ctx + "/business/employee";
		$(function() {
		    var options = {
		        url: prefix + "/query",                        // 查询的url
		        createUrl: prefix + "/addPage",                // 添加的url
		        updateUrl: prefix + "/editPage?id={id}",       // 编辑的url
		        removeUrl: prefix + "/remove?id={id}",       // 删除的url
		        sortName: "seq",                               // 排序的字段
		        modalName: "员工列表",                             // 模态框的名称
		        columns: [{
		            checkbox: true
		        },
		        {
		            field: 'id',
		            title: '员工id',
					visible: false                          // 隐藏
		        },
		        {
		            field: 'name',
		            title: '姓名',
		            sortable: true
		        },
		        {
		            field: 'email',
		            title: '邮箱',
		            sortable: true
		        },
		        {
		            field: 'age',
		            title: '年龄',
		            sortable: true
		        },
				{
		            field: 'sex',
		            title: '性别',
		            sortable: true,
					formatter: function(value, row, index) {
						if (value == 0) {
							return "男";
						} else {
							return "女"
						}
					}
		        },
				{
					field: 'admin',
					title: '是否超管',
					sortable: true,
					formatter: function(value, row, index) {
						if(value == 1){
							return "是"
						}else{
							return "否"
						}
					}
				},
				{
					field: 'hiredate',
					title: '入职时间',
					sortable: true,
				},
				{
					field: 'deptId',
					title: '所在部门',
					sortable: true,
					formatter: function(value, row, index) {
						if(value == 1){
							return "开发部"
						}else if (value == 2){
							return "财务部"
						}else if (value == 3){
							return "人事部"
						}else if (value == 4){
							return "市场部"
						}else if (value == 5){
							return "总经办"
						}else if (value == 6){
							return "战略部"
						}else if (value == 7){
							return "指挥部"
						}else if (value == 8){
							return "炮灰部"
						}
					}
				},
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		                var actions = [];
		                var saleClass = "";
		                var editClass = "";
						//如果处于审核中或者上架状态不允许编辑的
						if(row.auditStatus==1 || row.saleStatus == 1){
							editClass ="disabled";
						}
		                actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" ' +
								'onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
						actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" ' +
								'onclick="showDepartment(\'' + row.deptId + '\')"><i class="fa fa-edit"></i>查看部门详情</a> ');
						actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" ' +
								'onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-edit"></i>删除</a> ');

		                return actions.join(' ');
		            }
		        }]
		    };
		    $.table.init(options);
		});

		$("#bootstrap-table").on("check.bs.table uncheck.bs.table check-all.bs.table uncheck-all.bs.table load-success.bs.table", function () {
			var rows = $('#bootstrap-table').bootstrapTable('getSelections');
			// 判断个数如果大于1
			if(rows.length > 1 || rows.length == 0){
				$("#startAudit").addClass("disabled");
				return
			};
			var data =  rows[0];
			// 判断是否是套餐
			if(data.carPackage == 0){
				$("#startAudit").addClass("disabled");
				return;
			}
			// 如果状态等于审核中或者审核通过
			if(data.auditStatus ==1 || data.auditStatus == 2 ) {
				$("#startAudit").addClass("disabled");
				return;
			}
			$("#startAudit").removeClass("disabled");
		});

		$(".queryTime").datetimepicker({
			format: "yyyy-mm-dd hh:ii",
			autoclose: true
		});

		function showDepartment(deptId) {
			$.modal.open("部门详情","/business/employee/showDepartment?deptId=" + deptId);
		}

	</script>
</body>
</html>